﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chat_D_LuX_Client.Model
{
    class User : IDataErrorInfo
    {
        // Service Reference
        ChatServiceRef.Chat_ServiceClient sr = new ChatServiceRef.Chat_ServiceClient();

        private long _pkID;
        private string _username;
        private string _password;
        private string _confirmPassword;
        private string _email;
        private bool _isActive;
        private bool _isAdmin;

        public long PkId
        {
            get { return _pkID; }
            set { _pkID = value; }
        }

        public string Username
        {
            get { return _username; }
            set { _username = value; }
        }

        public string Password
        {
            get { return _password; }
            set { _password = value; }
        }

        public string ConfirmPassword
        {
            get { return _confirmPassword; }
            set { _confirmPassword = value; }
        }

        public string Email
        {
            get { return _email; }
            set { _email = value; }
        }
        public bool IsActive
        {
            get { return _isActive; }
            set { _isActive = value; }
        }

        public User()
        {

        }

        public string Error
        {
            get { throw new NotImplementedException(); }
        }

        public bool IsAdmin
        {
            get { return _isAdmin; }
            set { _isAdmin = value; }
        }

        public string this[string columnName]
        {
            get
            {
                string result = null;
                if (columnName == "Username")
                {
                    if (string.IsNullOrEmpty(Username))
                        result = "Please enter a username";
                    else if (sr.UserExists(Username))
                        result = "Username in use, please choose another";
                }
                if (columnName == "Password")
                {
                    if (string.IsNullOrEmpty(Password))
                        result = "Please enter a password";
                }
                if (columnName == "ConfirmPassword")
                {
                    if (string.IsNullOrEmpty(ConfirmPassword))
                        result = "Please  confirm password";
                    else if (ConfirmPassword != Password)
                        result = "Passwords do not match";
                }
                if (columnName == "Email")
                {
                    if (string.IsNullOrEmpty(Email))
                        result = "Please enter an email address";
                    else if (sr.EmailExists(Email))
                        result = "Email in use, please choose another";
                }
                return result;
            }
        }
    }
}
